package com.example.servlettemplate.servlet;

import com.example.servlettemplate.util.RequestUtil;
import com.example.servlettemplate.util.SystemConstants;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

@WebServlet("/page")
public class PageServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String page = RequestUtil.getString(req, "act");
        if (page == null) {
            // 默认首页
            page = "login";
        }
        req.getRequestDispatcher(SystemConstants.PAGE_PATH + page + ".jsp").forward(req, resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        doGet(req, resp);
    }
}
